﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.IsSymmetric
{
    class MainProject
    {
        static void Main(string[] args)
        {
            TreeNode treeNode = new TreeNode(1,new TreeNode(2,new TreeNode(3),new TreeNode(5)),new TreeNode(2,new TreeNode(4),new TreeNode(3)));
            Console.WriteLine(IsSymmetric(treeNode));
            Console.ReadKey();
        }
        public static bool IsSymmetric(TreeNode root)
        {
            return Symmetric(root.left, root.right);
        }

        public static bool Symmetric(TreeNode leftNode, TreeNode rightNode)
        {
            if (leftNode == null && rightNode == null)
            {
                return true;
            }
            else if (leftNode != null && rightNode != null)
            {
                if (leftNode.val != rightNode.val)
                {
                    return false;
                }
                else
                    return Symmetric(leftNode.left, rightNode.right) && Symmetric(leftNode.right, rightNode.left);
            }
            else
                return false;
        }
    }
}
